<template>
  <div class="outmain ba_f">
    <div class="shuju_title mar_b20">
      <div class="shuju_title_text">
        <span>取酒记录</span>
      </div>
    </div>
    <div class="">
      <el-form :inline="false" :model="form" class="demo-form-inline" label-width="130px">
        <div>
          <el-form-item label="手机号/姓名/昵称">
            <el-input v-model="form.keyword" size="medium" placeholder="请输入联系人/电话" @input="selectType"></el-input>
          </el-form-item>
        </div>
        <div class="flex ba_f">
          <el-form-item label="查询日期：">
            <div class="flex-bet">
              <div>
                <el-radio-group v-model="form.timeType" @change="selectType">
                  <el-radio-button label="1">今天</el-radio-button>
                  <el-radio-button label="2">近七天</el-radio-button>
                  <el-radio-button label="3">近十五天</el-radio-button>
                  <el-radio-button label="4">自定义时间</el-radio-button>
                </el-radio-group>
                <span class="mar_l20" v-if="form.timeType=='4'">
                  <el-date-picker v-model="form.time" type="daterange" range-separator="至" start-placeholder="开始日期"
                                  end-placeholder="结束日期" format="yyyy年MM月dd日" @change="selectType"></el-date-picker>
                </span>
              </div>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="tabledata mar_t20">
      <el-table :data="list" v-loading="listLoading" :element-loading-text="elementLoadingText"  stripe style="width: 100%">
        <el-table-column type="selection"></el-table-column>
        <el-table-column  label="存酒ID">
          <template slot-scope="scope">
            <div class="flex-col t_l">
              <div>{{scope.row.storageId}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column  label="订单信息" width='400'>
          <template slot-scope="scope">
            <div class="flex-col t_l">
              <div>取酒时间：<span class="">{{ scope.row.createdAt }}</span></div>
              <div>订单号：{{scope.row.outTradeNo}}</div>
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column label="用户信息" width='400'>-->
<!--          <template slot-scope="scope">-->
<!--            <div class="flex">-->
<!--              <div class="flex-col t_l">-->
<!--                <div>联系人：{{ scope.row.userName }}</div>-->
<!--                <div>联系电话：{{ scope.row.userTel }}</div>-->
<!--                <div class="overflowlnr">用户昵称：{{ scope.row.userName }}（UID：{{ scope.row.userId }}）</div>-->
<!--              </div>-->
<!--            </div>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="取酒数量" width='400'>
          <template slot-scope="scope">
            <div class="flex">
              <div class="flex-col t_l">
                <div>酒品名称：{{ scope.row.name }}</div>
                <div>取酒数量：<span class="color-red">{{ scope.row.takeNum }}</span></div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="寄存剩余" width='300'>
          <template slot-scope="scope">
            <div class="flex">
              <div class="flex-col t_l">
                <div>寄存剩余：{{ scope.row.surplusNum }}</div>
                <div>到期时间：<span class="color-red">{{ scope.row.endAt }}</span></div>
              </div>
            </div>
          </template>
        </el-table-column>
<!--        <el-table-column prop="note" label="订单备注" ></el-table-column>-->
        <el-table-column prop="state" label="状态" width='200'>
          <template slot-scope="scope">
            <div>
              <el-button type="text" v-show="scope.row.state==1" @click="handleEdit(scope.row.id,'adopt')">确认订单</el-button>
              <el-button type="text" v-show="scope.row.state==1" @click="handleEdit(scope.row.id,'reject')">拒绝订单</el-button>
            </div>
            <div>
              <div v-if="scope.row.state=='1'"><el-tag size="mini">待审核</el-tag></div>
              <div v-if="scope.row.state=='2'"><el-tag size="mini" type="success">已取出</el-tag></div>
              <div v-if="scope.row.state=='3'"><el-tag size="mini" type="info">已拒绝</el-tag></div>
              <div v-if="scope.row.state=='4'"><el-tag size="mini" type="danger">已失效</el-tag></div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text"  v-if="scope.row.state>1" @click="handleEdit2(scope.row)">取酒记录</el-button>
<!--            <span style="color:#F56C6C" v-show="scope.row.state=='2'">已确认</span>-->
<!--            <span style="color:#909399" v-show="scope.row.state=='3'">已拒绝</span>-->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background layout="prev, pager, next" :total="page.total" :page-size="page.pagesize" :current-page.sync="page.currentPage" @current-change="handleCurrentChange"></el-pagination>
      <edit ref="edit" @fetchData="fetchData"></edit>
    </div>
  </div>
</template>
<script>
import {brandOrderList, operatStorage} from '@/api/plug';
import Edit from "./components/edit";
import {mapState} from 'vuex'
import {changeDate} from "@/utils";
export default {
  components: {Edit},
  created() {
    this.fetchData();
    if (this.$route.query.id) {
      this.id = this.$route.query.id;
      this.fetchData();
    }
  },
  data() {
    return {
      form: {
        keyword: '',
        timeType: '1',
        time: [new Date(), new Date()],
      },
      list: [],
      listLoading: false,
      selectRows: '',
      elementLoadingText: '正在加载...',
      page: {
        total: 0,
        size: 10,
        currentPage: 1
      },
    };
  },
  methods: {
    async fetchData() {
      this.listLoading = true;
      var params = {
        page: this.page.currentPage,
        keyword: this.form.keyword,
        timeType: this.form.timeType,
        type: 2,
        startTime: this.form.timeType == '4' && this.form.time ? changeDate(this.form.time[0]).substr(0,10) : '',
        endTime: this.form.timeType == '4' && this.form.time ? changeDate(this.form.time[1]).substr(0,10) : '',
        storeId:'',
        storageId:this.id,
      };
      const { data, count } = await brandOrderList(params);
      this.list = data;
      this.page.total = count;
      this.listLoading = false;
    },
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.fetchData();
    },
    handleEdit2(row) {
      if (row.id) {
        this.$refs["edit"].showEdit(row,2);
      } else {
        this.$refs["edit"].showEdit();
      }
    },
    async handleEdit(id, type) {
      if (type == 'adopt') {
        const {msg} = await operatStorage({id, type,});
        this.$baseMessage(msg, "success");
        this.fetchData()
      } else if (type == 'reject') {
        this.$baseConfirm("您确定取消吗", null, async () => {
          const {msg} = await operatStorage({id, type,});
          this.$baseMessage(msg, "success");
          this.fetchData()
        });
      } else {
        this.$baseMessage('敬请期待', "success");
        this.fetchData()
      }
    },
    selectType() {
      this.fetchData();
    },
    handletj() {
      this.$router.push({ path: 'deliverytongji' });
    },
  }
};
</script>
